package com.example.yuan0604;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.example.yml.R;

public class LoginJzActivity extends AppCompatActivity implements View.OnClickListener {
    //本地存储

    private EditText name;
    private EditText pass;
    private CheckBox cb;
    private Button button;
    private SharedPreferences user;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_jz);
        initView();
    }

    private void initView() {
        name = (EditText) findViewById(R.id.name);
        pass = (EditText) findViewById(R.id.pass);
        cb = (CheckBox) findViewById(R.id.cb);
        button = (Button) findViewById(R.id.button);
        user = getSharedPreferences("user", Context.MODE_PRIVATE);
        String user_name = user.getString("name", null);
        String pass_word = user.getString("pass", null);
        name.setText(user_name);
        pass.setText(pass_word);
        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button:
                String username = name.getText().toString().trim();
                String password = pass.getText().toString().trim();
                if (cb.isChecked()) {
                    SharedPreferences.Editor edit = user.edit();
                    edit.putString("name", username);
                    edit.putString("pass", password);
                    edit.commit();

                }
                break;
        }
    }
}

